﻿using System;
using System.Collections;

namespace Arraylist集合的方法
{
    class Program
    {
        static void Main(string[] args)
        {
            //Arraylist Arraylist Arraylist Arraylist Arraylist Arraylist Arraylist Arraylist 
            //ArrayList list = new ArrayList();
            //ArrayList ArrayList ArrayList ArrayList ArrayList ArratList ArrayList ArrayList ArrayList ArrayList ArrayList ArrayList ArrayList
            //添加单个元素.Add Add Add Add Add Add Add Add Add Add Add Add Add Add Add Add Add Add Add
            //list.Add("蛋总");
            //list.Add(true);
            //list.Add(1);
            //添加集合元素 AddRange AddRange AddRange AddRange AddRange AddRange AddRange AddRange AddRange AddRange AddRange AddRange AddRange
            //list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            //list.AddRange(list); 
            //list.Clear();清空所有元素 Clear Clear Clear Clear Clear Clear Clear Clear Clear Clear Clear Clear Clear Clear Clear Clear Clear Clear Clear
            //list.Remove("蛋总");删除单个元素 ，写谁删谁 Remove Remove Remove Remove Remove Remove Remove Remove Remove Remove Remove Remove Remove Remove Remove Remove 
            //list.RemoveAt(0);根据下标去删除元素 RemoveAt RemoveAt RemoveAt RemoveAt RemoveAt RemoveAt RemoveAt RemoveAt RemoveAt RemoveAt RemoveAt RemoveAt RemoveAt
            //list.RemoveRange(0,4);根据下标去移除一定范围的元素 RemoveRange RemoveRange RemoveRange RemoveRange RemoveRange RemoveRange RemoveRange RemoveRange RemoveRange 
            //list.Sort();升序排列 Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort 
            //list.Reverse();反转Reverse Reverse Reverse Reverse Reverse Reverse Reverse Reverse Reverse Reverse Reverse Reveres Reverse Reverse Reverse
            //list.Insert(2, "耀");在指定的位置插入一个元素 Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert
            //list.InsertRange(3, new string[] { "小王", "小芳", "老马" });在指定的位置插入集合元素 InsertRande InsertRande InsertRande InsertRande InsertRande InsertRande InsertRande
            //bool b= list.Contains("蛋总");判断是否包含某个指定元素 Contains Conrains Contains Contains Contains Contains Contains Contains Contains Contains Contains
            //Console.WriteLine(b);
            //list.Add("耀");
            //if (!list.Contains("耀"))
            //{
            //    list.Add("耀");
            //}
            //else
            //{
            //    Console.WriteLine("有这位帅哥哦！");
            //}
            //for (int i = 0; i < list.Count; i++)
            //{
            //    Console.WriteLine(list[i]);
            //}

            //集合练习 创建一个集合，里面添加一些数字 求出平均值与和
            //ArrayList list = new ArrayList();
            //list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            //int sun = 0;
            //int zui = 0;
            //int zuix = 1;
            //for (int i = 0; i < list.Count; i++)
            //{
            //    sun += (int)list[i];
            //    if ((int)list[i] > zui)
            //    {
            //        zui =((int)list[i]);
            //    }
            //    if ((int)list[i] < zuix)
            //    {
            //        zuix = ((int)list[i]);
            //    }
            //}
            //Console.WriteLine("总和是{0}平均值是{1}",sun,sun/list.Count);
            //Console.WriteLine("最大值是{0}最小值是{1}",zui,zuix);
            //练习二 写一个长度为10的集合，要求里面随机存放10个数字（0-9）
            //但是要求所有的数字不重复
            //ArrayList list = new ArrayList();
            //Random ran = new Random();
            //for (int i = 0; i < 10; i++)
            //{
            //    int rnumber = ran.Next(0, 10);
            //    if (!list.Contains(rnumber))
            //    {
            //        list.Add(rnumber);
            //    }
            //    else
            //    {
            //        i--;
            //    }
            //}
            //for (int i = 0; i < list.Count; i++)
            //{
            //    Console.WriteLine(list[i]);
            //}
            Console.ReadKey();
        }
    }
}
